<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Object.defineProperty 实现双向数据绑定</title>
</head>
<body>
    
    <input type="text" id='inp' oninput="oninp(this.value)">

    <!-- <input type="text" id='inp'> -->


    <div id='content'></div>


<script>
    var form = { a:'default' };

    function oninp(value){
        form.inp = value;
    }

    Object.defineProperty(form,'inp',{
        get(){
            return this.a;
        },
        set(value){
            document.getElementById('inp').value = value;
            document.getElementById('content').innerText = value;
            this.a = value;
        }
    })

    document.getElementById('inp').value = form.inp;
    document.getElementById('content').innerText = form.inp;
    
</script>
</body>
</html>